<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增调动申请')" />
    <th:block th:include="include :: datetimepicker-css" />

</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-jobTransfer-add">
            <div class="form-group" hidden>
                <label class="col-sm-3 control-label is-required">调动人id：</label>
                <div class="col-sm-8">
                    <input name="empId" id="empId" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <!--<div class="form-group">
                    <label class="col-sm-1 control-label is-required">选择审核人：</label>
                    <div class="col-sm-2">
                        <div class='input-group'>
                            <input class='form-control' type='text'  id='userAuditName' readonly="readonly" required>
                            <span class='input-group-addon input-sm' onclick='selectDictTree("", this)'>
                            <i class='fa fa-search'>选择</i>
                        </span>
                        </div>
                    </div>
                </div>-->
                <label class="col-sm-2 control-label is-required">调动人姓名：</label>
                <div class="col-sm-4">
                    <div class='input-group'>
                        <input name="empName" id="empName" class="form-control" type="text" readonly>
                        <span id="selectDictTree" class='input-group-addon input-sm' onclick='selectDictTree("", this)'>
                                <i class='fa fa-search' >选择</i>
                        </span>
                    </div>
                </div>
                <label class="col-sm-2 control-label">入职日期：</label>
                <div class="col-sm-4">
                    <div class="input-group date">
                        <input name="nonManagerDate" id="nonManagerDate" class="form-control"  type="text" readonly>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">当前岗位：</label>
                <div class="col-sm-4">
                    <input name="currentPostId" id="currentPostId" class="form-control" type="hidden" >
                    <input name="currentPostName" id="currentPostName" class="form-control" type="text" readonly>
                </div>
                <label class="col-sm-2 control-label is-required">当前部门：</label>
                <div class="col-sm-4">
                    <input name="currentDeptId" id="currentDeptId" class="form-control" type="hidden" >
                    <input name="currentDeptName" id="currentDeptName" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">调动岗位：</label>
                <div class="col-sm-4">
                    <select id="jobTransferPostId" name="jobTransferPostId" class="form-control m-b" th:with="postAll=${@postService.getPostAll()}" required>
                        <option value="">请选择</option>
                        <option th:each="post : ${postAll}" th:text="${post.getPostName()}" th:value="${post.getPostId()}"  th:hidden="${post.getStatus() == '1'}"></option>
                    </select>
                </div>
                <label class="col-sm-2 control-label is-required">调动部门：</label>
                <div class="col-sm-4">
                    <select id="jobTransferDeptId" name="jobTransferDeptId" class="form-control m-b" th:with="deptAll=${@deptService.getDeptAll()}">
                        <option value="">请选择</option>
                        <option th:each="dept : ${deptAll}" th:text="${dept.getShowName()}" th:value="${dept.getDeptId()}"  th:hidden="${dept.getStatus() == '1' || dept.getDelFlag() != '0' }"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">调动日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="jobTransferrDate" class="form-control" placeholder="yyyy-MM-dd" readonly="readonly" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required" >调动原因：</label>
                <div class="col-sm-8">
                    <input name="jobTransferDescription" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">调动类型：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_job_transfer')}">
                        <input type="radio" th:id="${'jobTransferType_' + dict.dictCode}" name="jobTransferType" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                        <label th:for="${'jobTransferType_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>

            <div th:replace="include/fileUploadUtil::fileUploadUtil('上传附件',5)" ></div>

            <div class="form-group" hidden>
                <label class="col-sm-3 control-label">发布状态：</label>
                <div class="col-sm-8">
                    <div class="">
                        保存<input type="radio" name="status" value="0" checked required>&nbsp;&nbsp;&nbsp;&nbsp;
                        发布<input type="radio" name="status" value="1" required>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">

        var hrAdminFlag = [[${hrAdminFlag}]];
        var userId = [[${userId}]];

        var prefix = ctx + "hr/jobTransfer"
        $("#form-jobTransfer-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                debugger
                if ($('input[name="nonManagerDate"]').val() > $('input[name="jobTransferrDate"]').val()) {
                    $.modal.alertWarning("调动日期不能在入职日期之前");
                    return;
                }
                //上传图片
                $("#testListAction").click();
                if (!$("#demoList").html()){
                    //没有图片直接提交表单
                    submitFrom();
                }
            }
        }

        function submitFrom() {
            $.operate.save(prefix + "/add", $('#form-jobTransfer-add').serialize());
        }

        function submitHandlerPush() {
            // debugger
            $(" input[name='status']").each(function(){
                if($(this).val() == 1){
                    $(this).prop( "checked", true );
                }
            });
            if ($.validate.form()) {
                if ($('input[name="nonManagerDate"]').val() > $('input[name="jobTransferrDate"]').val()) {
                    $.modal.alertWarning("调动日期不能在入职日期之前");
                    return;
                }
                $.operate.save(prefix + "/add", $('#form-jobTransfer-add').serialize());
            }
        }

        $("input[name='jobTransferrDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });



        // 选择字典处理函数
        function selectDictTree(columnId, obj) {
            // alert("awefwewfew");
            var url = ctx + "system/user/selectUserTree";
            var options = {
                title: '调动人姓名',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

       /* function doSubmit(index, layero){
            // debugger
            var body = layer.getChildFrame('body', index);
            var userId = body.find('#userId').val();
            var userNameShow = body.find('#userNameShow').val();
            layer.close(index);
            $("#empId").val(userId);
            $("#userAuditName").val(userNameShow);
            // document.getElementById("userName").value=userName;
        }
*/

        function doSubmit(index, layero){
            debugger
            var body = layer.getChildFrame('body', index);
            var empId = body.find('#userId').val();
            var empName = body.find('#empName').val();
            var empNameShow = body.find('#empNameShow').val();

            var nonManagerDate = body.find('#nonManagerDate').val();
            var deptName = body.find('#deptName').val();
            var postName = body.find('#postName').val();
            var deptId = body.find('#deptId').val();
            var postId = body.find('#postId').val();


            layer.close(index);
            $("#empId").val(empId);
            $("#empName").val(empName);

            $("#nonManagerDate").val(nonManagerDate);
            $("#currentDeptName").val(deptName);
            $("#currentPostName").val(postName);
            $("#currentDeptId").val(deptId);
            $("#currentPostId").val(postId);
        }


        $(function() {
            debugger
            if (hrAdminFlag == 1){
                //不是人事
                $.get(ctx + "system/user/selectUserById?userId="+userId, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        debugger
                        $("#selectDictTree").hide();

                        $("#empId").val(result.data.userId);
                        $("#empName").val(result.data.userName);

                        $("#nonManagerDate").val(result.data.nonManagerDateVO);
                        $("#currentDeptName").val(result.data.dept.deptName);
                        $("#currentPostName").val(result.data.sysPostVO.postName);
                        $("#currentDeptId").val(result.data.dept.deptId);
                        $("#currentPostId").val(result.data.sysPostVO.postId);

                    }
                });
            } else {

            }
        });


    </script>
</body>
</html>